<template>
<div>
    <div class="product-content">
      <el-form size="small" ref="form" :model="form" label-width="150px">
        <!--基础设置-->
        <Basic :form="form"></Basic>
        <!--时间设置-->
        <Datetime :form="form"></Datetime>
        <!--其它-->
        <Other :form="form"></Other>
      </el-form>
    </div>

    <!--提交-->
    <div class="common-button-wrapper">
      <el-button size="small" @click="cancelFunc">{{$t('plus.cancel_text')}}</el-button>
      <el-button
        size="small"
        type="primary"
        @click="onSubmit"
        :disabled="loading"
        >{{$t('plus.submit')}}</el-button
      >
    </div>
  </div>
</template>

<script>
import AssembleApi from "@/api/assemble.js";
import Basic from "./part/Basic.vue";
import Datetime from "./part/Datetime.vue";
import Product from "./part/Product.vue";
import Other from "./part/Other.vue";
export default {
  components: {
    /*基础设置*/
    Basic,
    /*时间设置*/
    Datetime,
    /*活动商品*/
    Product,
    /*其它*/
    Other
  },
  data() {
    return {
      form: {
        /*活动名称*/
        title: "",
        /*广告图片ID*/
        imageId: 0,
        /*活动广告图*/
        filePath: "",
        /*活动日期*/
        startDate: "",
        endDate: "",
        /*是否生效，默认1为生效，0为不生效*/
        status: 1,
        /*拼团失败处理方式：0失败退款1自动拼团成功*/
        failType: 0,
        /*是否单团0否1是*/
        isSingle: 0,
        /*默认排序*/
        sort: 100,
        /*凑团时间*/
        togetherTime: 24,
        joinEndTime: "",
        activeDate: [],
        /*商品源数据*/
        tableData: [],
        /*商品列表*/
        productList: []
      },
      /*判断是否正在加载*/
      loading: false
    };
  },
  created() {},
  methods: {
    /*提交表单*/
    onSubmit() {
      let self = this;
      self.$refs.form.validate(valid => {
        if (valid) {
          let params = self.form;
          params.startTime = params.activeDate[0];
          params.endTime = params.activeDate[1];
          self.loading = true;
          AssembleApi.addActive(params, true).then(data => {
            self.loading = false;
            ElMessage({
              message: $t("plus.add_success"),
              type: "success"
            });
            self.$router.push("/plus/assemble/index");
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    },
    /*取消*/
    cancelFunc() {
      this.$router.back(-1);
    }
  }
};
</script>

